package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.LabelService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.LabelAddVO;
import com.junzhiit.nengji.cms.web.vo.LabelEditVO;
import com.junzhiit.nengji.cms.web.vo.LabelListVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/label")
public class LabelController extends BaseController{
	
	@Autowired
	private LabelService labelService;
	
	@ApiOperation(value="查询所有")
	@RequestMapping(method=RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp,LabelListVO labelListVO){
		return labelService.findAll(dtp,labelListVO);
	}
	
	@ApiOperation(value="根据id查询")
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResultVO findById(@PathVariable String id){
		return labelService.findById(id);
	}
	
	@ApiOperation(value="添加")
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(LabelAddVO labelAddVO){
		AssertUtil.notBlank(labelAddVO.getName(), "name is required");
		return labelService.add(labelAddVO);
	}
	
	@ApiOperation(value="修改")
	@RequestMapping(value="/{id}",method=RequestMethod.PUT)
	public ResultVO edit(@PathVariable String id,LabelEditVO labelEditVO){
		AssertUtil.notBlank(labelEditVO.getName(), "name is required");
		return labelService.edit(id,labelEditVO);
	}
	
	@ApiOperation(value="获取所有")
	@RequestMapping(value="/all",method=RequestMethod.GET)
	public ResultVO getAll(LabelListVO labelListVO){
		return labelService.getAll(labelListVO);
	}
	
	
	@RequestMapping(value="/delete/{id}",method=RequestMethod.PUT)
	public ResultVO updateTodelete(@PathVariable String id){
		return labelService.updateTodelete(id);
	}
	
}
